<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>AUI快速完成布局</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/mui/mui.min.css" />
    <style type="text/css">
        .text-white {
            color: #ffffff !important;
        }
        .aui-grid [class*=aui-col-] {
            padding: 0.75rem 0;
        }
        .aui-list-item.wechat-top {
            background-color: #f3f3f7;
        }
        .aui-list .wechat-avatar {
            width:4rem;
        }
        .wechat-avatar .aui-row-padded {
            background-color: #dddee0;
            padding: 0.1rem;
            border-radius: 0.2rem;
            margin-left: -0.05rem;
            margin-right: -0.05rem;
        }
        .wechat-avatar .aui-row-padded [class*=aui-col-xs-] {
            padding: 0.05rem;
        }
        .wechat-avatar,
        .wechat-avatar > img {
            border-radius:0.2rem;
        }
    </style>
</head>
<body>

  <section class="mui-card aui-margin-b-15 aui-content-padded">
      <div class="aui-list aui-list-noborder aui-media-list" style="border:none;border-radius:8px;">
              <div class="aui-media-list-item-inner aui-margin-l-10">
                  <div class="aui-list-item-media wechat-avatar">
                      <img id="head_img" src="../image/demo1.png">
                  </div>
                  <div class="aui-list-item-inner">
                      <div class="aui-list-item-text">
                          <div class="aui-list-item-title" id="cn_name_id"></div>
                          <div class="aui-list-item-right" id="r_name_id"></div>
                      </div>
                      <div class="aui-list-item-text">

                      </div>
                  </div>
              </div>
              <div class="aui-info aui-margin-l-10" style="padding-top:0">
                  <div class="aui-info-item">
                      <span class="aui-margin-l-5"></span>
                  </div>
                  <div class="aui-info-item" id="username_id"></div>
              </div>
      </div>
  </section>
  <section class="aui-content">
        <ul class="aui-list aui-list-in aui-margin-b-15">
            <li class="aui-list-item">

                <div class="aui-list-item-inner">
                    <div class="aui-list-item-title">手机&nbsp;&nbsp;&nbsp;&nbsp;<span id="phone_id"></span></div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-title">部门&nbsp;&nbsp;&nbsp;&nbsp;<span id="d_name_id"></span></div>
                </div>
            </li>
        </ul>
    </section >
    <section class="aui-content aui-content-padded">
        <p><div onclick="openWin('send_msg')" class="aui-btn aui-btn-info aui-btn-block aui-btn-sm aui-margin-b-15">发消息</div></p>
        <p><div onclick="call()" class="aui-btn aui-btn-block aui-btn-outlined aui-btn-sm">拨打电话</div></p>
    </section>
</body>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript">
    apiready = function () {
        var username = api.pageParam.username;
        var ryId = api.pageParam.ryId;
        var cn_name = api.pageParam.cn_name;
        var d_name = api.pageParam.d_name;
        var r_name = api.pageParam.r_name;
        var phone = api.pageParam.phone;
        var	user_img = api.pageParam.user_img;
        if(user_img !== 'null'){
            $("#head_img").attr("src",ServeIp+'include/data/headImg/'+user_img);
        }

        $("#username_id").html(username);
        $("#cn_name_id").html(cn_name);
        $("#d_name_id").html(d_name);
        $("#r_name_id").html(r_name);
        $("#phone_id").html(phone);

        //个人页进入会话页面，首先获取最后一条消息
        api.sendEvent({
            name:'getLastMsg',
            extra:{
                targetId:ryId,
                conversationType:'PRIVATE',
                count: 1
            }
        })

        //监听最后一条消息内容
        api.addEventListener({
            name:'lastMsg'
        },function(ret){
            if(ret && ret.value){
                var value = ret.value;
                if(value.data.length>0){
                    $api.setStorage('personal_msg_id', value.data[0].messageId);
                    $api.setStorage('personal_c_type', value.data[0].conversationType);
                    $api.setStorage('personal_target_id', value.data[0].targetId);
                    $api.setStorage('personal_sent_time', value.data[0].sentTime);
                }else {
                    $api.setStorage('personal_msg_id', '');
                    $api.setStorage('personal_c_type', '');
                    $api.setStorage('personal_target_id', '');
                    $api.setStorage('personal_sent_time', 'value.data[0].sentTime');
                }
            }
        });

    }

    //打电话
    function call(){
      var phone = api.pageParam.phone;
      api.call({
          type: 'tel_prompt',
          number: phone
      });
    }

    function openWin(name) {
        //个人页进入会话页面，获取历史消息
        api.sendEvent({
            name:'getHistoryMessages',
            extra:{
                targetId:$api.getStorage('personal_target_id'),
                conversationType:  $api.getStorage('personal_c_type'),
                latestMessageId:$api.getStorage('personal_msg_id')
            }
        })


      //  alert($api.getStorage('personal_sent_time'));
        api.openWin({
            name: name,
            url: name+'_win.html',
            pageParam: {
               phone:api.pageParam.phone,
               targetId:api.pageParam.ryId,
               username:api.pageParam.cn_name,
               user_img : api.pageParam.user_img,
               sentTime:$api.getStorage('personal_sent_time'),
               conversationType:'PRIVATE'
            },
        });
    }
</script>
</html>
